package com.ztsjglxt.core.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;

import com.ztsjglxt.core.IBlackboxmanage;
import com.ztsjglxt.dao.AeqmanageMapper;
import com.ztsjglxt.dao.BlackboxmanageMapper;
import com.ztsjglxt.entity.Aeqmanage;
import com.ztsjglxt.entity.Blackboxmanage;
import com.ztsjglxt.utils.BeanToMap;
import com.ztsjglxt.utils.Laypage;
import com.ztsjglxt.utils.PageUtil;

@Service
@EnableTransactionManagement
@Transactional
public class BlackboxmanageImpl implements IBlackboxmanage {

	@Autowired
	private BlackboxmanageMapper blackboxmanagedao;
	
	public List<Map<String, Object>> selectlist(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return blackboxmanagedao.selectlist(map);
	}

	
	public Laypage getlistpager(PageUtil table) throws Exception{
			table.setPage((table.getCurpage()-1)*table.getRows());
			List<Map<String, Object>> list = blackboxmanagedao.selectlist(BeanToMap.transBean2Map(table));
			int records = blackboxmanagedao.selectlistcount(BeanToMap.transBean2Map(table));
		
		
		return new Laypage(list, records, table);
	}

	
	public int insert(Blackboxmanage record) {
		// TODO Auto-generated method stub
		return blackboxmanagedao.insert(record);
	}

	
	public int insertSelective(Blackboxmanage record) {
		// TODO Auto-generated method stub
		return blackboxmanagedao.insertSelective(record);
	}
	
	public int getcount(Map<String,Object> map){
		return blackboxmanagedao.selectlistcount(map);
	}

	
	public Blackboxmanage selectlistbyid(Blackboxmanage record) {
		// TODO Auto-generated method stub
		return blackboxmanagedao.selectlistbyid(record);
	}

	@Override
	public int updateBlackboxmanage(Blackboxmanage entity) {
		// TODO Auto-generated method stub
		return blackboxmanagedao.updateBlackboxmanage(entity);
	}

	@Override
	public int deleteBlackboxmanage(String ids) throws Exception {
		int count = 1;
		try {
			String[] id = ids.split(",");
			for (int i = 0; i < id.length; i++) {
				blackboxmanagedao.deleteByPrimaryKey(Integer.valueOf(id[i]));
			}
		} catch (Exception e) {
			count=0;
			e.printStackTrace();
			throw new RuntimeException();
		}
		return count;
	}


	@Override
	public int updatestate(String ids, String state) {
		Map<String,Object> map = new HashMap<>();
		map.put("ids",ids);
		map.put("state", state);
		return blackboxmanagedao.updatestate(map);
	}


	@Override
	public int updatestate(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return blackboxmanagedao.updatestate(map);
	}

}
